import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 *
 * 直接在route写入想加入的路由，并设置对应权限信息就行了，已经设计好自动更具路由渲染显示页面了。。很棒@！！！
 *
 * Note: sub-menu only appear when route children.length >= 1
 *
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 * 所有的角色都可以访问的路由
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        name: 'Profile',
        meta: { title: 'profile', icon: 'user', noCache: true }
      }
    ]
  }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 * 根据角色动态生成可以访问的路由
 */
export const asyncRoutes = [
  {
    path: '/permission',
    component: Layout,
    redirect: '/permission/page',
    alwaysShow: true, // will always show the root menu
    name: 'Permission',
    meta: {
      title: 'permission',
      icon: 'lock',
      // roles: ['admin', 'editor'] // you can set roles in root nav
      roles: ['超级管理员']
    },
    children: [
      {
        path: 'role',
        component: () => import('@/views/permission/role'),
        name: 'RolePermission',
        meta: {
          title: 'rolePermission',
          roles: ['超级管理员']
        }
      }
    ]
  },
  // 供热营业厅
  {
    path: '/heatingBusinessHall',
    component: Layout,
    redirect: '/heatingBusinessHall/employeeDepartmentManagement',
    alwaysShow: true, // will always show the root menu
    name: 'heatingBusinessHall',
    meta: {
      title: '供热营业厅管理',
      roles: ['超级管理员'], // 暂时仅仅超级管理员能够访问
      icon: 'international'
    },
    children: [
      {
        path: 'employeeDepartmentManagement',
        component: () => import('@/views/ht/yytgl/yggl'),
        name: 'employeeDepartmentManagement',
        meta: { title: '员工部门管理', roles: ['超级管理员'] },
        children: [
          {
            path: 'employeeInformationManagement',
            component: () => import('@/views/ht/yytgl/yggl'),
            name: 'employeeInformationManagement',
            meta: { title: '员工管理' },
            children: [
              {
                path: 'employeeTypeManagement',
                component: () => import('@/views/ht/yytgl/yggl/yglxgl'),
                name: 'employeeTypeManagement',
                meta: { title: '员工类型管理' }
              },
              {
                path: 'employeeInfomationQuery',
                component: () => import('@/views/ht/yytgl/yggl/ygxxcx'),
                name: 'employeeInfomationQuery',
                meta: { title: '员工信息查询' }
              }
            ]
          },
          {
            path: 'departmentInformationManagement',
            component: () => import('@/views/ht/yytgl/bmgl'),
            name: 'departmentInformationManagement',
            meta: { title: '部门管理' },
            children: [
              {
                path: 'departmentTypeManagement',
                component: () => import('@/views/ht/yytgl/bmgl/bmlxxxgl'),
                name: 'departmentTypeManagement',
                meta: { title: '部门类型管理' }
              },
              {
                path: 'departmentInfomationQuery',
                component: () => import('@/views/ht/yytgl/bmgl/bmxxcx'),
                name: 'departmentInfomationQuery',
                meta: { title: '部门信息查询' }
              }
            ]
          }
        ]
      },
      {
        path: 'salaryInformationManagement',
        component: () => import('@/views/ht/yytgl/qjgl'),
        meta: { title: 'OA办公管理' },
        children: [
          {
            path: 'employeeVacationInfoManagement',
            component: () => import('@/views/ht/yytgl/qjgl/qjxxcx'),
            name: 'employeeVacationInfoManagement',
            meta: { title: '请假信息管理' }
          },
          {
            path: 'employeeSalaryInformationManagement',
            component: () => import('@/views/ht/yytgl/gzgl/gzxxcx'),
            name: 'employeeSalaryInformationManagement',
            meta: { title: '工资信息管理' }
          },
          {
            path: 'employeeAttendanceInformationManagement',
            component: () => import('@/views/ht/yytgl/cqgl/cqxxcx'),
            name: 'employeeAttendanceInformationManagement',
            meta: { title: '出勤信息管理' }
          }
        ]
      }
    ]
  },
  // 小区住户管理模块
  {
    path: '/villageHouseholdManagement',
    component: Layout,
    redirect: '/villageHouseholdManagement/villagehouseholdInformationDisplay',
    alwaysShow: true, // will always show the root menu
    name: 'villageHouseholdManagement',
    meta: {
      title: '小区住户管理',
      roles: ['超级管理员'], // 暂时仅仅超级管理员能够访问
      icon: 'user'
    },
    children: [
      {
        path: 'villagehouseholdInformationDisplay',
        component: () => import('@/views/nested/menu1/index'),
        name: 'villagehouseholdInformationDisplay',
        meta: { title: '住户信息展示' }
      },
      {
        path: 'villageInformationManagement',
        component: () => import('@/views/ht/xqzhgl/xqxxgl/index'),
        name: 'villageInformationManagement',
        meta: { title: '小区信息管理' }
      },
      {
        path: 'householdBasicPersonalInformationManagement',
        component: () => import('@/views/ht/xqzhgl/zhxxgl/index'),
        name: 'householdBasicPersonalInformationManagement',
        meta: { title: '住户个人信息管理', roles: ['超级管理员'] }
      },
      {
        path: 'householdBasicPersonalHeatingInformationManagement',
        component: () => import('@/views/ht/xqzhgl/grxxgl/index'),
        name: 'householdBasicPersonalHeatingInformationManagement',
        meta: { title: '住户供热信息管理', roles: ['超级管理员'] }
      },
      {
        path: 'householdBasicPersonalHouseInformationManagement',
        component: () => import('@/views/ht/xqzhgl/fwxxgl/index'),
        name: 'householdBasicPersonalHouseInformationManagement',
        meta: { title: '住户房屋信息管理', roles: ['超级管理员'] }
      },
      {
        path: 'householdBasicPersonalNoticeInformationManagement',
        component: () => import('@/views/ht/xqzhgl/tzxxgl/index'),
        name: 'householdBasicPersonalNoticeInformationManagement',
        meta: { title: '住户通知信息管理', roles: ['超级管理员'] }
      },
      {
        path: 'householdBasicPersonalReportInformationManagement',
        component: () => import('@/views/ht/xqzhgl/btqtxxgl/index'),
        name: 'householdBasicPersonalReportInformationManagement',
        meta: { title: '住户报停强停管理', roles: ['超级管理员'] }
      },
      {
        path: 'menu5',
        meta: { title: '住户统计管理', roles: ['超级管理员'] },
        children: [
          {
            path: 'employeeInformationManagement',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'employeeInformationManagement',
            meta: { title: '住户基本信息导出' }
          },
          {
            path: 'departmentInformationManagement',
            component: () => import('@/views/nested/menu1/menu1-2'),
            name: 'departmentInformationManagement',
            meta: { title: '住户供热信息导出' }
          },
          {
            path: 'menu1-3',
            component: () => import('@/views/nested/menu1/menu1-3'),
            name: 'Menu1-3',
            meta: { title: '住户报停信息导出' }
          }
        ]
      }
    ]
  },
  // 计费管理模块
  {
    path: '/billingManagement',
    component: Layout,
    redirect: '/billingManagement/householdInformationDisplay',
    alwaysShow: true, // will always show the root menu
    name: 'billingManagement',
    meta: {
      title: '计费管理',
      roles: ['超级管理员'], // 暂时仅仅超级管理员能够访问
      icon: 'money' // 图片尚未定义 - 后期完善
    },
    children: [
      {
        path: 'billingInformationDisplay',
        component: () => import('@/views/nested/menu1/index'),
        name: 'billingInformationDisplay',
        meta: { title: '计费信息展示' }
      },
      {
        path: 'CollectionManagement',
        component: () => import('@/views/ht/jfzdgl/jfxxgl/index'),
        name: 'CollectionManagement',
        meta: { title: '收款' }
      },
      {
        path: 'CollectionDoc&ReconciliationQuery',
        component: () => import('@/views/ht/jfzdgl/zdxxgl/index'),
        name: 'CollectionDoc&ReconciliationQuery',
        meta: { title: '收款单&对账查询' }
      },
      {
        path: 'DailyInquiryOfHeatingCharge',
        component: () => import('@/views/ht/jfzdgl/cnfrbxxgl/index'),
        name: 'DailyInquiryOfHeatingCharge',
        meta: { title: '采暖费收费日报查询' }
      },
      {
        path: 'BillingInformationStatisticsManagement',
        name: 'BillingInformationStatisticsManagement',
        meta: { title: '计费信息统计管理', roles: ['超级管理员'] },
        children: [
          {
            path: 'StatisticsManagement',
            component: () => import('@/views/nested/menu1/menu1-1'),
            name: 'StatisticsManagement',
            meta: { title: '收款详情信息导出' }
          }
        ]
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: '/#/',
        meta: { title: '感谢您的使用', icon: 'link', roles: ['超级管理员'] }
      }
    ]
  },
  // // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }

]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
